package org.child_motivation.business.model;

import no.kantega.publishing.security.data.User;

import java.util.ArrayList;
import java.util.List;

public class Group {
    private int id = -1;
    private String name;
    private User owner;
    private List<User> approverList;
    private List<User> memberList;

    public Group() {
        approverList = new ArrayList();
        memberList = new ArrayList();

    }

    public Group(int id, String name, User owner, List<User> approverList, List<User> memberList) {
        this.id = id;
        this.name = name;
        this.owner = owner;
        this.approverList = approverList;
        this.memberList = memberList;
        if(approverList == null){
            approverList = new ArrayList();
        }
        if(memberList== null){
            memberList = new ArrayList();
        }
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public User getOwner() {
        return owner;
    }

    public List<User> getApproverList() {
        return approverList;
    }

    public List<User> getMemberList() {
        return memberList;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public void setApproverList(List<User> approverList) {
        this.approverList = approverList;
    }

    public void setMemberList(List<User> memberList) {
        this.memberList = memberList;
    }

    public String getApproversAsString(){
        return createCommaSeparatedString(approverList);
    }

    public String getMembersAsString(){
        return createCommaSeparatedString(memberList);
    }


    private String createCommaSeparatedString(List<User> list) {
        String text = "";
        for(int i = 0; i < list.size(); i++){
            if(i != 0 ){
                text += ",";
            }
            text += list.get(i).getId();
        }
        return text;
    }

    public boolean isNew(){
        return id == -1;
    }

    public void setId(int id) {
        this.id = id;
    }
}
